package com.hy.service1;

import feign.FeignException;
import feign.Response;
import feign.jackson.JacksonDecoder;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Map;

public class MyDecode extends JacksonDecoder {

    @Override
    public Object decode(Response response, Type type) throws IOException, FeignException {
       Map<String, Object> map = (Map<String, Object>) super.decode(response, Map.class);
       if((Integer)map.get("status") == 200) {
           return map.get("result");
       } else {
           try {
               throw new Exception(String.format("errorCode: %s, errorDesc:%s", map.get("status"), map.get("resultDesc")));
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
       return null;
    }
}
